﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZX.CRM.Bussiness;
using System.Text;
using ZX.CRM.Library;
using ZX.Web.UI.Controls;

namespace ZX.WebApp.Crm
{
    public partial class StudentPrint : BasePage
    {
        BCrmProductLayout bll = new BCrmProductLayout();
        protected void Page_Load(object sender, EventArgs e)
        {
            string strId = this.GetStringFromQueryString("id", "");
            string strPrintType = this.GetStringFromQueryString("printType", "");
            string strImgType = this.GetStringFromQueryString("imgType","");
            string strLayoutName = this.GetStringFromQueryString("layoutName","");
            string strLayoutTime = this.GetStringFromQueryString("layoutTime", "");
            string strJson = this.GetStringFromQueryString("json", "");
            string strGroupName = this.GetStringFromQueryString("groupName","");
            string strDeptName = this.GetStringFromQueryString("deptName", "");
            LoadData(strId, strPrintType, strImgType, strLayoutName, strLayoutTime, strJson, strGroupName, strDeptName);
        }
        private void LoadData(string strId, string strPrintType, string strImgType, string strLayoutName, string strLayoutTime, string strJson, string strGroupName, string strDeptName)
        {
            //默认为执模
            string card = @"<div style='float: left; width: 390px; height: 250px;'>" +
                                "<img src='" + this.zhimo.Value + "' alt='' width='390' height='250' />" +
                                "<div class='coursename'>" + strLayoutName + "&nbsp;&nbsp;&nbsp;&nbsp;</div>" +
                                "<div class='layoutname'>" + strLayoutTime + "&nbsp;&nbsp;</div>" +
                                "<div class='group'>@group</div>" +
                                "<div class='name'>@name</div>" +
                            "</div>";
            //总裁战略模式
            string card1 = @"<div style='float: left; width: 380px; height: 565px;'>" +
                                "<img src='" + this.zhanmo.Value + "' alt='' width='380' height='560' />" +
                                "<div class='coursename1'>" + strLayoutName + "</div>" +
                                "<div class='layoutname1'>" + strLayoutTime + "</div>" +
                                "<div class='group1'>@group</div>" +
                                "<div class='name1'>@name</div>" +
                            "</div>";
            //助教、辅导员
            string card2 = @"<div style='text-align: center; width: 780px;'>" +
                                "<div style='float: left; width: 390px; height: 255px;'>" +
                                    "<img src='" + this.zhujiao.Value + "' alt='' width='390' height='255' />" +
                                    "<div class='group2'>@group</div>" +
                                    "<div class='name2'>@name</div>" +
                                "</div>" +
                            "</div>";
            //复训
            string card3 = @"<div style='float: left; width: 390px; height: 250px;'>" +
                                "<img src='" + this.fuxun.Value + "' alt='' width='390' height='250' />" +
                                "<div class='coursename3'>" + strLayoutName + "&nbsp;&nbsp;&nbsp;&nbsp;</div>" +
                                "<div class='layoutname3'>" + strLayoutTime + "&nbsp;&nbsp;</div>" +
                                "<div class='group3'>@group</div>" +
                                "<div class='name3'>@name</div>" +
                            "</div>";

            StringBuilder sb = new StringBuilder("");
            if (strPrintType == "1") //默认打印
            {
                int IsTrain = 0;
                if (strImgType == "4")
                {
                    IsTrain = 1;
                }
                IList<V_CrmDeliverMajorStudent> listStudent = bll.GetCrmDeliverMajorStudentToPrint(strPrintType, strImgType, new Guid(strId), strGroupName, strDeptName, IsTrain);
                if (listStudent != null && listStudent.Count > 0)
                {
                    if (strImgType == "1" || strImgType == "4")  //总裁执行模式|复训
                    {
                        sb.Append("<div style='text-align: center; width: 780px;'>");
                        for (int i = 0; i < listStudent.Count; i++)
                        {
                            string temp = string.Empty;
                            string tempName = string.Empty;
                            tempName = listStudent[i].PrintClassName;
                            if (strImgType == "1")
                            { 
                                temp = card;
                            }
                            else if (strImgType == "4")
                            {
                                temp = card3;
                            }
                            if (tempName.Length == 2)
                            {
                                tempName = tempName.Substring(0, 1) + "&nbsp;&nbsp;&nbsp;" + tempName.Substring(1, 1);
                            }
                            temp = temp.Replace("@name", tempName).Replace("@group", listStudent[i].GroupName.ToString());
                            sb.Append(temp);
                        }
                        sb.Append("</div>");
                    }
                    else if (strImgType == "2")   //总裁战略模式
                    {
                        sb.Append("<div style='text-align: center; width: 760px;'>");
                        for (int i = 0; i < listStudent.Count; i++)
                        {
                            string temp = string.Empty;
                            temp = card1;
                            string tempName = string.Empty;
                            tempName = listStudent[i].PrintClassName;
                            if (tempName.Length == 2)
                            {
                                tempName = tempName.Substring(0, 1) + "&nbsp;&nbsp;&nbsp;" + tempName.Substring(1, 1);
                            }
                            temp = temp.Replace("@name", tempName).Replace("@group", listStudent[i].GroupName.ToString());
                            sb.Append(temp);
                        }
                        sb.Append("</div>");
                    }
                }
                else
                {
                    this.lblNoMsg.Visible = true;
                }
            }
            else //自定义打印
            {
                if (strImgType == "1" || strImgType == "4")  //总裁执行模式|复训
                {
                    sb.Append("<div style='text-align: center; width: 780px;'>");
                    string[] list = strJson.Split('@');
                    for (int i = 0; i < list.Length; i++)
                    {
                        string[] arrayStudent = list[i].Split('$');
                        string temp = string.Empty;
                        string tempName = string.Empty;
                        tempName = arrayStudent[0];
                        if (strImgType == "1")
                        {
                            temp = card;
                        }
                        else if (strImgType == "4")
                        {
                            temp = card3;
                        }
                        if (tempName.Length == 2)
                        {
                            tempName = tempName.Substring(0, 1) + "&nbsp;&nbsp;&nbsp;" + tempName.Substring(1, 1);
                        }
                        temp = temp.Replace("@name", tempName).Replace("@group", arrayStudent[1]);
                        if (arrayStudent[0] != "" || arrayStudent[1] != "")
                        {
                            sb.Append(temp);
                        }
                    }
                    sb.Append("</div>");
                }
                else if (strImgType == "2") //总裁战略模式
                {
                    sb.Append("<div style='text-align: center; width: 760px;'>");
                    string[] list = strJson.Split('@');
                    for (int i = 0; i < list.Length; i++)
                    {
                        string[] arrayStudent = list[i].Split('$');
                        string temp = string.Empty;
                        temp = card1;
                        string tempName = string.Empty;
                        tempName = arrayStudent[0];
                        if (tempName.Length == 2)
                        {
                            tempName = tempName.Substring(0, 1) + "&nbsp;&nbsp;&nbsp;" + tempName.Substring(1, 1);
                        }
                        temp = temp.Replace("@name", tempName).Replace("@group", arrayStudent[1]);
                        if (arrayStudent[0] != "" || arrayStudent[1] != "")
                        {
                            sb.Append(temp);
                        }
                    }
                    sb.Append("</div>");
                }
                else if (strImgType == "3")  //助教、辅导员
                {
                    sb.Append("<div style='text-align: center; width: 780px;'>");
                    string[] list = strJson.Split('@');
                    for (int i = 0; i < list.Length; i++)
                    {
                        string[] arrayStudent = list[i].Split('$');
                        string temp = string.Empty;
                        temp = card2;
                        string tempName = string.Empty;
                        string tempGroup = string.Empty;
                        tempName = arrayStudent[0];
                        tempGroup = arrayStudent[1];
                        if (tempName.Length == 2)
                        {
                            tempName = tempName.Substring(0, 1) + "&nbsp;&nbsp;&nbsp;" + tempName.Substring(1, 1);
                        }
                        if (tempGroup.Length == 2)
                        {
                            tempGroup = tempGroup.Substring(0, 1) + "&nbsp;&nbsp;" + tempGroup.Substring(1, 1);
                        }
                        temp = temp.Replace("@name", tempName).Replace("@group", tempGroup);
                        if (arrayStudent[0] != "" || arrayStudent[1] != "")
                        {
                            sb.Append(temp);
                        }
                    }
                    sb.Append("</div>");
                }
            }
            this.ltStudent.Text = sb.ToString();
        }
    }
}